<script setup lang="ts">
import { onMounted } from 'vue';

import useCode from './hooks/useCode';
import useForm from './hooks/useForm';

const { codeUrlRad, getCode } = useCode();
const { form, rules, loginForm, onSubmit } = useForm();

onMounted(() => {
  getCode();
});
</script>

<template>
  <div class="login-page">
    <!-- 背景 -->
    <div class="background"></div>

    <!-- 主容器 -->
    <div class="container">
      <el-form ref="loginForm" class="login_form" :model="form" :rules="rules">
        <el-form-item prop="username">
          <el-input v-model="form.username" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" show-password placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <div class="code">
            <div class="code_input">
              <el-input v-model="form.code" placeholder="请输入验证码"> </el-input>
            </div>
            <div class="code_image">
              <img :src="codeUrlRad" alt="验证码" @click="getCode()" />
            </div>
          </div>
        </el-form-item>
        <el-form-item>
          <el-checkbox v-model="form.remember">记住密码</el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button class="login_submit" type="primary" @click="onSubmit(loginForm, getCode)">登 录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style scoped lang="scss">
.login-page {
  height: 100vh;
  width: 100%;
  background: #000;

  .background {
    background: url('./backgroun3.jpg') no-repeat;
    background-position: center;
    background-size: cover;
    height: 100vh;
    width: 100%;
    filter: blur(10px);
  }

  .container {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 75%;
    height: 550px;
    background: url('./backgroun3.jpg') no-repeat;
    background-position: center;
    background-size: cover;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;

    .login_form {
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      width: 50%;

      .code {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 20px;

        // 判断是否是移动端
        @media (max-width: 768px) {
          flex-direction: column;
        }

        .code_input {
          width: 80%;
        }

        .code_image {
          width: 20%;
          cursor: pointer;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }

      .login_submit {
        width: 100%;
      }
    }

    .login-form {
      padding: 80px;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
  }
}
</style>
